package com.WJY.boot.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @author 星河.
 * @Description
 * @create 2025/6/22 上午10:58
 */

@RestController
public class ChatAiController {

    @Autowired
    private ChatClient chatClient;

    //非流式响应
    @GetMapping("/xyy")
    public String xyy(@RequestParam(value = "msg") String message) {
        return chatClient.prompt().user(message).call().content();
    }

    //流式响应      produces:设置编码方式
    @GetMapping(value = "/xyyS", produces = "text/html;charset=utf8")
    public Flux<String> xyyStream(@RequestParam(value = "msg") String message) {
        return chatClient.prompt().user(message).stream().content();
    }

}
